<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta name="description" content="Adonate" />
		<meta name="keywords" content="Adonate,MDG,IMAP" />
		<meta name="author" content="Ajou University" />
		<meta charset="UTF-8" />
		<title>ADonate :: Authentication Page</title>
		<script type="text/javascript" src="./js/jquery-1.7.2.min.js"></script>
		<script>
			$(function() {
				adonate = {};
				
				$.ajaxPrefilter('json', function(options, orig, jqXHR) {
					return 'jsonp';
				});
				
				$("input[name=btn_authentication]").click(function() {
					user_email = $("input[name=user_email]").val();
					
					$.getJSON(
						'http://211.189.127.75/xoauth.py',
						{user : user_email, step : 1},
						function(data) {
							adonate.key = data.key;
							adonate.secret = data.secret;
							adonate.url = data.url;
							
							console.log(adonate);
							
							window.open(adonate.url);
						}
					);
				});
				
				$("input[name=btn_verification]").click(function() {
					user_email = $("input[name=user_email]").val();
					verifier = $("input[name=verifcation_code]").val();
					
					$.getJSON(
						'http://211.189.127.75/xoauth.py',
						{ 
							user : encodeURI(user_email), 
							key : encodeURI(adonate.key), 
							secret : encodeURI(adonate.secret), 
							verifier : encodeURI(verifier), 
							step : 2
						},
						function(data) {
							console.log(data);
							
							$.getJSON(
								'./StoreOAuthToken',
								{
									user : user_email,
									oauth_token : data.oauth_token,
									oauth_token_secret : data.oauth_token_secret
								},
								function(data) {
									console.log(data);
								}
							);
							alert("기부가 완료되었습니다.");
						}
					);
				});
				
			});
		</script>
	</head>
<body>
	<h2>Authentication Page</h2>
	<div id="authentication">
		<input type="text" name="user_email" size=50 value=""/>
		<input type="button" name="btn_authentication" value="Authentication"/>
	</div>
	
	<div id="verification">
		<input type="text" name="verifcation_code" size=50 value=""/>
		<input type="button" name="btn_verification" value="Verification"/>
	</div>
	<ul>
		<li><a href="./index.jsp">Index</a></li>
		<li><a href="./upload.jsp">Upload</a></li>
	</ul>
</body>
</html>